package cn.smbms.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
import cn.smbms.service.UserService;
@Service
public class UserServiceImpl implements UserService{

	@Resource
	public UserMapper userMapper;
	
	public User login(String userCode, String password) {
		User user=userMapper.findByUserCode(userCode);
		if (user==null) {
			return null;
		}
		if (user.getUserPassword().equals(password)) {
			return user;
		}
		return null;
	}

	public List<User> findList(String name, Integer roleId,Integer pageNo,Integer pageSize) {
		
		int startIndex = (pageNo-1)*pageSize;
		
		return userMapper.findList( name, roleId, startIndex, pageSize);
	}
	public int count(String userName, Integer userRole) {
		
		return userMapper.count(userName, userRole);
	}

	@Override
	public User findListUser(Integer id) {
		
		return userMapper.findListUser(id);
	}
	
	public int addUser(User user) {
		
		return userMapper.addUser(user);
	}

	@Override
	public int prinById(User user) {
		
		return userMapper.prinById(user);
	}

	@Override
	public boolean deleteUser(int uid) {
		boolean fign=false;
		if (userMapper.deleteUser(uid)>0) {
			fign=true;
		}
		return fign;
	}

	@Override
	public Boolean userCodeExit(String userCode) {
		boolean result=true;
		User user=userMapper.findByUserCode(userCode);
		if (user==null) {
			result=false;
		}
		return result;
	}

	@Override
	public int updatePwd(String newpassword, Integer id) {
	
		return userMapper.updatePwd(newpassword, id);
	}
}
